# -*- coding: utf-8 -*-
# @Time : 2023/11/22 11:37
# @Author : ZH
# @File : start.py
# @Software: PyCharm
import random
import string
import inspect
from enum import Enum
from location_position import utils


class LocationLanguage(Enum):
    CN = 'cn'  # 中文
    EN = 'en'  # 英文


def get_all_classes(module):
    classes = []
    for name, obj in inspect.getmembers(module):
        if inspect.isclass(obj):
            classes.append(obj)
    return classes


def get_supporting_classes(module):
    supporting_classes = []
    for name, obj in inspect.getmembers(module):
        if inspect.isclass(obj):
            if hasattr(obj, 'get_support') and inspect.ismethod(getattr(obj, 'get_support')):
                supporting_classes.append(obj)
    return supporting_classes


def is_english(s):
    return all(c in string.ascii_letters for c in s)


class LocationPosition:
    def __init__(self):
        __doc__ = "地址转换成经纬度"

    def start(self, *, location, language: LocationLanguage = LocationLanguage.CN, **kwargs):
        supporting_classes = get_supporting_classes(utils)
        support_obj = []
        for cls in supporting_classes:
            support_value = cls.get_support()
            if language.value in support_value:
                support_obj.append(cls)
        if support_obj:
            obj = random.choice(support_obj)
            instance = obj(location=location, **kwargs)
            return instance.start_main(location, **kwargs)
        else:
            return None

